package com.xpc.controller.vo;

import com.baomidou.mybatisplus.extension.api.ApiController;
import com.baomidou.mybatisplus.extension.api.R;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xpc.mapper.UserAllInfoMapper;
import com.xpc.pojo.vo.StudentInfo;
import com.xpc.pojo.vo.UserAllInfo;
import com.xpc.service.IUserInfoService;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Project：UniversityGradeAdministrationSystem
 * Date：2022/5/27
 * Time：2:00
 * Description：TODO
 *
 * @author 南北辰的键盘
 * @version 1.0
 */
@RestController
@RequestMapping("userInfo")
public class UserAllInfoController extends ApiController {

    @Autowired
    private UserAllInfoMapper userAllInfoMapper;
//    private IUserInfoService userInfoService;


    // 增
    @PostMapping
    public R insert(@RequestBody UserAllInfo userAllInfo){

        return null;
    }

    // 删
    // 改



    /**
     * 获取全体学生信息（学生中心-需要权限）
     * @param page
     * @param userAllInfo
     * @return
     */
    @GetMapping("studentsInfo")
    public R selectAllStudentInfo(Page<UserAllInfo> page, UserAllInfo userAllInfo){
        List<UserAllInfo> userAllInfoList = this.userAllInfoMapper.selectUserAllInfo();
        return success(userAllInfoList);
    }


    /**
     * 获取某个指定学生完整信息（需要权限）
     * @param account_id
     * @return
     */
    @GetMapping("getStudent/{account_id}")
    public R selectStudentInfoByID(@PathVariable String account_id){
        Subject subject = SecurityUtils.getSubject();
        String principal = (String) subject.getPrincipal();
//        System.out.println("============="+principal+"===============");
        UserAllInfo userAllInfo = this.userAllInfoMapper.selectUserAllInfoById(account_id);
        return success(userAllInfo);
    }

    @GetMapping("self")
    public R selectStudentInfoByUser(){
        Subject subject = SecurityUtils.getSubject();
        String principal = (String) subject.getPrincipal();
//        System.out.println("============="+principal+"===============");
        UserAllInfo userAllInfo = this.userAllInfoMapper.selectUserAllInfoById(principal);
        return success(userAllInfo);
    }



}
